home *** CD-ROM | disk | FTP | other *** search
- Path: nntp.teleport.com!sschaem
- From: sschaem@teleport.com (Stephan Schaem)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: PPC compilers
- Date: 11 Jan 1996 11:52:57 GMT
- Organization: Teleport - Portland's Public Access (503) 220-1016
- Message-ID: <4d2tmp$o03@maureen.teleport.com>
- References: <john.hendrikx.40ka@grafix.xs4all.nl> <4ck47h$g07@maureen.teleport.com> <19960106.4EE928.CF59@sisyphus.demon.co.uk> <4cokkg$415@maureen.teleport.com> <19960107.533250.14585@sisyphus.demon.co.uk> <4cqrti$f6u@maureen.teleport.com> <19960109.55D920.1497F@sisyphus.demon.co.uk>
- NNTP-Posting-Host: kelly.teleport.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Dave.Sparks@sisyphus.demon.co.uk wrote:
- : >>>>> "SS" == Stephan Schaem <sschaem@teleport.com> writes:
-
- : SS> Dave.Sparks@sisyphus.demon.co.uk wrote:
-
- : SS> I cant see how people can write code without knowing what data
- : SS> or type they manipulate...
-
- : >> Real-world programmers do it all the time. If you ever want to
-
- : SS> So you do math operation without knowing that your destination need
- : SS> to be a float or a 2 byte int?
-
- : >> Yes. This is a trivial example of polymorphism.
-
- : SS> polymorphism?
-
- : SS> int a,b,c;
-
- : SS> ... a = b /c; a *= result; ... struct.float = a;
-
- : SS> I dunno , I just find it puzzling to declar variable without giving
- : SS> a care of what its usage will be. You programing practice is VERY
- : SS> unwise...
-
- : If I want to store a value of type clock_t, I declare a value of
- : type clock_t - knowing that it could be signed or unsigned int or
- : long, or float or double.
-
- Ok, you have to know its a type C can handle with its operator...
- Now, what if you want to do some operation on the vague type, of
- vague range?
-
- : I guess I really have to spoon feed you a real life example.
-
- : clock_t start_time, end_time;
- : double time_used;
- : ...
- : start_time = clock ();
- : ...
- : end_time = clock ();
- : time_used = ((double) (end_time - start_time)) / CLOCKS_PER_SEC;
- : ...
- : printf ("Time used was %.3f seconds/n", time_used);
-
- When you write time_used, you know that time_used is a variable of
- type double... you know that double is a real. You know that
- end_time and start_time are of type clock_t and you know that type
- clock_t is something you can use with C operators.
-
- I dont see in what you wrote where a C coder can forget his variable type
- and type definition when he write compared to a asm programmer.
-
- : is hardware-independent ANSI C. Don't worry about the few
- : floating-point operations: anyone who is worried about performance
- : will have hardware which can execute floating-point ops
- : asynchronously. If the C compiler does its job properly and
- : generates the instructions in the best order, the floating-point
- : ops will be executed in parallel and the total execution time may
- : even be _less_ than the time which would have been needed if
- : fixed-point had been used.
-
- I can worry alot.. even on 150mhz mips risc chips I use tables to do some
- operation VS using int multiplication...
- But in this I couldn't care if the float operation are execute by superslow
- math function on a 68000.
- The point is, you didn't write the example blindly...
-
- BTW I never denied the advantage of having custom type... But realize that
- when you code function in asm, there are pretty much system depandent.
- My all point was about C and asm programming and the 'advantage' of C
- programmer not having to know there variable type and type definition:
- something I find unwise.
-
- : SS> You said yourself after peeking at the .h that clock_t was
- : SS> a ulong.
-
- : I didn't peek the .h , I read the docs. And my code doesn't
- : depend on clock_t being unsigned long.
-
- then the doc will probably tell you that clock_t is system depandent,
- is a type that is supported by C operators, and define its range and
- function .
-
- the same info is avail for asm programmer... But he will have to use
- the asm type VS the renamed type. I never said asm have type redefinition.
-
- : >> target CPU? How quaint ...
-
- : SS> But target CPU is something that come up often in the real world of
- : SS> programming... oh, forgot you think you are part of it. C compiler
-
- : If your product is a large, expensive program with a small niche
- : market, and your various potential customers use Amiga, SUN,
- : RS6000 or HP, you can't afford to target your code on a single
- : processor type. You may have to write some parts of your program
- : in assembly code, either for performance or because some functions
- : can't be performed in C, but you'll be reluctant to do so because
- : the assembly code will have to be written and tested four times.
-
- Thats true... and I agree. This is also true for OS specific code,
- at least once for each new machine you will work on. (I make a habbit
- to never call the OS function directly)
-
- : SS> The way you get optimal speed is optimizing the optimal algorithim.
- : SS> If you stop at the algorithm you loose... Optimizing at this stage
- : SS> will give an exponential result on the work you done on the
- : SS> algorithm. And usually this stage is done in assembler.
-
- : Getting the algorithm right can improve performance by orders of
- : magnitude (i.e. not thinking about the algorithm can degrade
- : performance by a factor of ten or more). Writing everything in
- : assembler might save 20% over writing everything in C and using a
- : good compiler. Writing the bulk of your code in C and a small
- : proportion (less than 5%) in assembler is usually a good compromise.
-
- 20% is way to low in the real world.. from 0 to 400% is more realistic.
-
- I only write pure asm code on the amiga when I know its only for the amiga,
- and the algo are not overly complex.
-
- my latest stuff: 99% ansi C + mips asm (targeted only for low SGI box), C
- only for W3.1 and macos 7.x (80% was portable the rest was OS specific),
- asm only for an amiga video driver for a mac emulator...
-
- If you want I give you the algo for the c2p in the mac driver and you write
- a version that is only 20% slower? Its is no tricky code like addx, or swap
- etc.. all the logic is portable to C.
-
- Stephan
-